Skip to content

fix(start): align request handler types with registered server context#7428

Open
SeanCassiere wants to merge 9 commits into
mainfrom
refactor/adjust-types-for-start-register-declaration
Open

fix(start): align request handler types with registered server context#7428
SeanCassiere wants to merge 9 commits into
mainfrom
refactor/adjust-types-for-start-register-declaration

Conversation

@SeanCassiere
Copy link
Copy Markdown
Member

@SeanCassiere SeanCassiere commented May 17, 2026

In reference to #7399

Summary by CodeRabbit

  • Bug Fixes

    • Aligned request handler types across React, Solid, and Vue integrations so server request context typing works consistently.
    • Made server entry typings explicitly define request parameter signatures for safer invocation.
  • Documentation

    • Updated server-entry documentation examples to target the correct framework packages and show typed server request context.
  • Tests

    • Updated end-to-end smoke tests to exercise and validate the typed request context.

Review Change Stack

…t-start

Add a Start-owned Register interface that extends router-core's
Register, then export and consume it from `start-client-core`.

This lets declarations against `@tanstack/react-start`, including
`server.requestContext`, flow into Start-specific type consumers instead
of requiring users to augment `@tanstack/router-core` or
`@tanstack/react-router` directly.

Router-core Register augmentations remain compatible because Start's
Register extends the core Register.
Import Register from `@tanstack/start-client-core` in
`createStartHandler` instead of `@tanstack/router-core`.

This makes the server handler default to Start's augmentation surface,
allowing `@tanstack/react-start` Register declarations such as
`server.requestContext` to flow into RequestHandler typing.
…e the request context (#7427)

This reverts commit 2506478 since these
changes now can infer the types off of Start's Register interface
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 17, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: baba9b84-445d-4e2a-b275-10e32e27fcb6

📥 Commits

Reviewing files that changed from the base of the PR and between d6b0635 and 714d5e2.

📒 Files selected for processing (1)
  • e2e/react-start/import-protection/src/routes/type-only-protected-import.tsx

📝 Walkthrough

Walkthrough

Aligns request handler types across Start packages by introducing RequestHandlerParameters, constraining generics to Register, switching framework server entries to explicit fetch signatures, updating core utilities, and exercising typed requestContext in E2E servers and documentation.

Changes

Request Handler Type Alignment

Layer / File(s) Summary
Core RequestHandler type refactoring
packages/start-server-core/src/request-handler.ts
Introduces RequestHandlerParameters<TRegister> tuple type to conditionally include RequestOptions in the handler's parameter list, replacing the previous HasRequired utility. RequestHandler is refactored to use this tuple in a spread pattern and constrain to Register.
Generic constraint and type annotations in start-server-core
packages/start-server-core/src/createStartHandler.ts, packages/start-server-core/src/request-response.ts, packages/start-server-core/src/index.tsx
createStartHandler and requestHandler update their generics to extends Register with explicit type annotations for requestOpts and return values; index re-exports are reformatted.
Framework-specific server entry point signatures
packages/react-start/src/default-entry/server.ts, packages/solid-start/src/default-entry/server.ts, packages/vue-start/src/default-entry/server.ts
React, Solid, and Vue server entries replace RequestHandler<Register> with explicit fetch function signatures (request: Request, opts?: RequestOptions<Register>). Each framework's createServerEntry forwards (request, opts) explicitly instead of using rest parameters.
E2E test validation of context passing
e2e/react-start/basic/src/server.ts, e2e/solid-start/basic/src/server.ts, e2e/vue-start/basic/src/server.ts, e2e/react-start/import-protection/src/routes/type-only-protected-import.tsx
E2E tests augment their framework Register.server.requestContext types and pass context objects into handler.fetch, exercising the updated handler signatures; an example route's requestHandler typing is aligned to RequestHandler<Register>.
Documentation updates for module augmentation pattern
docs/start/framework/react/guide/server-entry-point.md, docs/start/framework/solid/guide/server-entry-point.md
React and Solid docs update module augmentation examples to target @tanstack/react-start and @tanstack/solid-start respectively when extending Register.server.requestContext.
Release notes
.changeset/thick-sloths-write.md
Changeset documents patch releases for @tanstack/start-client-core, @tanstack/start-server-core, @tanstack/react-start, @tanstack/solid-start, and @tanstack/vue-start with a fix(start) note about aligning request handler types with registered server context.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • TanStack/router#7427: Updates the same React Server Entry Point documentation's TypeScript module augmentation pattern to target @tanstack/react-start for custom request-context typing.
  • TanStack/router#7380: Introduces RequestOptions extensions (e.g., inlineCss) that interact with the requestOpts parameter forwarding and typing updates in this PR.

Suggested reviewers

  • beaussan

Poem

🐰 I hopped through types to tidy the trail,
Passed context like carrots without fail,
Tuples now guide what options should show,
Handlers and entries all set to go,
A joyful hop — the types sing hale and well.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main objective of the PR: aligning request handler types with registered server context across the TanStack Start packages.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/adjust-types-for-start-register-declaration

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud
Copy link
Copy Markdown
Contributor

nx-cloud Bot commented May 17, 2026

View your CI Pipeline Execution ↗ for commit 714d5e2

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ✅ Succeeded 8m 45s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 48s View ↗

☁️ Nx Cloud last updated this comment at 2026-05-22 00:49:21 UTC

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 17, 2026

🚀 Changeset Version Preview

5 package(s) bumped directly, 9 bumped as dependents.

🟩 Patch bumps

Package Version Reason
@tanstack/react-start 1.168.10 → 1.168.11 Changeset
@tanstack/solid-start 1.168.10 → 1.168.11 Changeset
@tanstack/start-client-core 1.170.2 → 1.170.3 Changeset
@tanstack/start-server-core 1.169.2 → 1.169.3 Changeset
@tanstack/vue-start 1.168.10 → 1.168.11 Changeset
@tanstack/react-start-client 1.168.2 → 1.168.3 Dependent
@tanstack/react-start-rsc 0.1.10 → 0.1.11 Dependent
@tanstack/react-start-server 1.167.7 → 1.167.8 Dependent
@tanstack/solid-start-client 1.168.2 → 1.168.3 Dependent
@tanstack/solid-start-server 1.167.7 → 1.167.8 Dependent
@tanstack/start-plugin-core 1.171.3 → 1.171.4 Dependent
@tanstack/start-static-server-functions 1.167.7 → 1.167.8 Dependent
@tanstack/vue-start-client 1.167.7 → 1.167.8 Dependent
@tanstack/vue-start-server 1.167.7 → 1.167.8 Dependent

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 17, 2026

Bundle Size Benchmarks

  • Commit: f975de29c46c
  • Measured at: 2026-05-22T00:41:49.085Z
  • Baseline source: history:b47b338d15de
  • Dashboard: bundle-size history
Scenario Current (gzip) Delta vs baseline Initial gzip Raw Brotli Trend
react-router.minimal 87.29 KiB 0 B (0.00%) 87.16 KiB 274.02 KiB 75.93 KiB █████▁▁▁▁▁▁
react-router.full 90.82 KiB 0 B (0.00%) 90.69 KiB 285.52 KiB 78.75 KiB ▆▆▆▆█▁▁▁▁▁▁
solid-router.minimal 35.53 KiB 0 B (0.00%) 35.41 KiB 106.33 KiB 31.95 KiB ▅████▁▁▁▁▁▁
solid-router.full 40.28 KiB 0 B (0.00%) 40.15 KiB 120.53 KiB 36.20 KiB ▁▂▂▂▃▄▄▄▄██
vue-router.minimal 53.33 KiB 0 B (0.00%) 53.20 KiB 151.46 KiB 47.88 KiB ▇▇▇▇▁▅▅▅▅██
vue-router.full 58.45 KiB 0 B (0.00%) 58.32 KiB 167.63 KiB 52.35 KiB ▆▆▆▆▁▆▆▆▆██
react-start.minimal 102.03 KiB 0 B (0.00%) 101.89 KiB 322.47 KiB 88.29 KiB ▁▄▄▄▃▆▆▆▆██
react-start.deferred-hydration 103.07 KiB 0 B (0.00%) 102.20 KiB 324.12 KiB 89.21 KiB ████▁▁▁▁▂▂
react-start.full 105.43 KiB 0 B (0.00%) 105.29 KiB 332.79 KiB 91.17 KiB ▆████▁▁▁▁▃▃
react-start.rsbuild.minimal 99.64 KiB 0 B (0.00%) 99.46 KiB 316.93 KiB 85.73 KiB ▆▆▆▆▁██████
react-start.rsbuild.full 102.93 KiB 0 B (0.00%) 102.76 KiB 327.34 KiB 88.59 KiB ▇▇▇▇▁▂▂▂▂██
solid-start.minimal 49.67 KiB 0 B (0.00%) 49.54 KiB 152.46 KiB 43.87 KiB ▁███▇▄▄▄▄▄▄
solid-start.deferred-hydration 53.74 KiB 0 B (0.00%) 50.40 KiB 161.00 KiB 47.74 KiB ███▇▁▁▁▁▁▁
solid-start.full 55.46 KiB 0 B (0.00%) 55.33 KiB 169.35 KiB 48.80 KiB ▁███▆▆▆▆▆▇▇

Current gzip tracks all emitted client JS chunks. Initial gzip tracks only the entry/import graph. Trend sparkline is historical current gzip ending with this PR measurement; lower is better.

@SeanCassiere SeanCassiere changed the title refactor: start should export and use its own Register interface refactor(start): export and use its own Register interface May 17, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 17, 2026

More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/@tanstack/arktype-adapter@7428

@tanstack/eslint-plugin-router

npm i https://pkg.pr.new/@tanstack/eslint-plugin-router@7428

@tanstack/eslint-plugin-start

npm i https://pkg.pr.new/@tanstack/eslint-plugin-start@7428

@tanstack/history

npm i https://pkg.pr.new/@tanstack/history@7428

@tanstack/nitro-v2-vite-plugin

npm i https://pkg.pr.new/@tanstack/nitro-v2-vite-plugin@7428

@tanstack/react-router

npm i https://pkg.pr.new/@tanstack/react-router@7428

@tanstack/react-router-devtools

npm i https://pkg.pr.new/@tanstack/react-router-devtools@7428

@tanstack/react-router-ssr-query

npm i https://pkg.pr.new/@tanstack/react-router-ssr-query@7428

@tanstack/react-start

npm i https://pkg.pr.new/@tanstack/react-start@7428

@tanstack/react-start-client

npm i https://pkg.pr.new/@tanstack/react-start-client@7428

@tanstack/react-start-rsc

npm i https://pkg.pr.new/@tanstack/react-start-rsc@7428

@tanstack/react-start-server

npm i https://pkg.pr.new/@tanstack/react-start-server@7428

@tanstack/router-cli

npm i https://pkg.pr.new/@tanstack/router-cli@7428

@tanstack/router-core

npm i https://pkg.pr.new/@tanstack/router-core@7428

@tanstack/router-devtools

npm i https://pkg.pr.new/@tanstack/router-devtools@7428

@tanstack/router-devtools-core

npm i https://pkg.pr.new/@tanstack/router-devtools-core@7428

@tanstack/router-generator

npm i https://pkg.pr.new/@tanstack/router-generator@7428

@tanstack/router-plugin

npm i https://pkg.pr.new/@tanstack/router-plugin@7428

@tanstack/router-ssr-query-core

npm i https://pkg.pr.new/@tanstack/router-ssr-query-core@7428

@tanstack/router-utils

npm i https://pkg.pr.new/@tanstack/router-utils@7428

@tanstack/router-vite-plugin

npm i https://pkg.pr.new/@tanstack/router-vite-plugin@7428

@tanstack/solid-router

npm i https://pkg.pr.new/@tanstack/solid-router@7428

@tanstack/solid-router-devtools

npm i https://pkg.pr.new/@tanstack/solid-router-devtools@7428

@tanstack/solid-router-ssr-query

npm i https://pkg.pr.new/@tanstack/solid-router-ssr-query@7428

@tanstack/solid-start

npm i https://pkg.pr.new/@tanstack/solid-start@7428

@tanstack/solid-start-client

npm i https://pkg.pr.new/@tanstack/solid-start-client@7428

@tanstack/solid-start-server

npm i https://pkg.pr.new/@tanstack/solid-start-server@7428

@tanstack/start-client-core

npm i https://pkg.pr.new/@tanstack/start-client-core@7428

@tanstack/start-fn-stubs

npm i https://pkg.pr.new/@tanstack/start-fn-stubs@7428

@tanstack/start-plugin-core

npm i https://pkg.pr.new/@tanstack/start-plugin-core@7428

@tanstack/start-server-core

npm i https://pkg.pr.new/@tanstack/start-server-core@7428

@tanstack/start-static-server-functions

npm i https://pkg.pr.new/@tanstack/start-static-server-functions@7428

@tanstack/start-storage-context

npm i https://pkg.pr.new/@tanstack/start-storage-context@7428

@tanstack/valibot-adapter

npm i https://pkg.pr.new/@tanstack/valibot-adapter@7428

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/@tanstack/virtual-file-routes@7428

@tanstack/vue-router

npm i https://pkg.pr.new/@tanstack/vue-router@7428

@tanstack/vue-router-devtools

npm i https://pkg.pr.new/@tanstack/vue-router-devtools@7428

@tanstack/vue-router-ssr-query

npm i https://pkg.pr.new/@tanstack/vue-router-ssr-query@7428

@tanstack/vue-start

npm i https://pkg.pr.new/@tanstack/vue-start@7428

@tanstack/vue-start-client

npm i https://pkg.pr.new/@tanstack/vue-start-client@7428

@tanstack/vue-start-server

npm i https://pkg.pr.new/@tanstack/vue-start-server@7428

@tanstack/zod-adapter

npm i https://pkg.pr.new/@tanstack/zod-adapter@7428

commit: 73a9c6d

@SeanCassiere SeanCassiere marked this pull request as ready for review May 17, 2026 23:29
@SeanCassiere SeanCassiere marked this pull request as draft May 17, 2026 23:34
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 17, 2026

Merging this PR will not alter performance

✅ 5 untouched benchmarks
⏩ 1 skipped benchmark1


Comparing refactor/adjust-types-for-start-register-declaration (73a9c6d) with main (b47b338)2

Open in CodSpeed

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports.

  2. No successful run was found on main (31f5684) during the generation of this report, so b47b338 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

Use the shared router-core Register for Start request handler types while preserving the documented custom server entry shape.

Request options now derive required context from Register.server.requestContext, but framework ServerEntry wrappers still accept the universal fetch handler form with optional request options.
@SeanCassiere SeanCassiere force-pushed the refactor/adjust-types-for-start-register-declaration branch from 89310e0 to d6b0635 Compare May 21, 2026 23:43
@SeanCassiere SeanCassiere changed the title refactor(start): export and use its own Register interface fix(start): align request handler types with registered server context May 21, 2026
@SeanCassiere SeanCassiere marked this pull request as ready for review May 21, 2026 23:44
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/start-server-core/src/createStartHandler.ts`:
- Around line 325-327: startRequestResolver is declared as
RequestHandler<Register> with requestOpts?: RequestOptions<Register>, but the
code later casts it to RequestHandler<TRegister>, which hides
RequestOptions<TRegister> constraints such as required server.requestContext;
instead make startRequestResolver generic over TRegister (or accept
RequestOptions<TRegister>) within createStartHandler so its signature matches
RequestHandler<TRegister> without casting—update the function/type parameters
(startRequestResolver, RequestOptions, RequestHandler, createStartHandler,
TRegister, Register) so the resolver uses the generic TRegister request option
types (including requestContext when present) and remove the unsafe cast.

In `@packages/start-server-core/src/request-response.ts`:
- Around line 125-128: The wrapper currently declares requestOpts?: any which
bypasses the RequestHandler<TRegister> contract and then re-establishes types
via a cast; change the wrapper signature to accept the strongly-typed options
instead of any so the wrapper itself matches RequestHandler<TRegister> (i.e.,
replace requestOpts?: any with the correct generic opts type for TRegister and
adjust the wrapper return type to Promise<Response> | Response as needed),
remove the subsequent as RequestHandler<TRegister> cast, and ensure the internal
call sites use the typed opts variable (references: the wrapper function taking
(request: Request, requestOpts), the RequestHandler<TRegister> type and the
TRegister generic).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7286b653-e8ba-4a37-ae1f-5478603a1e1f

📥 Commits

Reviewing files that changed from the base of the PR and between 9d0ba3e and d6b0635.

📒 Files selected for processing (8)
  • .changeset/thick-sloths-write.md
  • packages/react-start/src/default-entry/server.ts
  • packages/solid-start/src/default-entry/server.ts
  • packages/start-server-core/src/createStartHandler.ts
  • packages/start-server-core/src/index.tsx
  • packages/start-server-core/src/request-handler.ts
  • packages/start-server-core/src/request-response.ts
  • packages/vue-start/src/default-entry/server.ts
✅ Files skipped from review due to trivial changes (2)
  • packages/start-server-core/src/index.tsx
  • .changeset/thick-sloths-write.md

Comment on lines 325 to +327
const startRequestResolver: RequestHandler<Register> = async (
request,
requestOpts,
request: Request,
requestOpts?: RequestOptions<Register>,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify generic erasure/cast pattern in this file
rg -n -C2 'RequestHandler<Register>|RequestOptions<Register>|as RequestHandler<TRegister>' packages/start-server-core/src/createStartHandler.ts

Repository: TanStack/router

Length of output: 398


🏁 Script executed:

#!/bin/bash
set -euo pipefail

FILE="packages/start-server-core/src/createStartHandler.ts"

echo "== Context around startRequestResolver (lines ~280-360) =="
nl -ba "$FILE" | sed -n '280,360p'

echo "== Context around return requestHandler cast (lines ~540-620) =="
nl -ba "$FILE" | sed -n '540,620p'

echo "== Find TRegister/Register/RequestOptions usage in file =="
rg -n "TRegister|Register|RequestOptions<|requestHandler<|requestHandler\(" "$FILE"

echo "== Find type of requestHandler helper usage (look for its generic signature or import) =="
rg -n "function requestHandler|const requestHandler|requestHandler\s*<" "$FILE"

Repository: TanStack/router

Length of output: 179


🏁 Script executed:

#!/bin/bash
set -euo pipefail

FILE="packages/start-server-core/src/createStartHandler.ts"

echo "== Context around startRequestResolver (rough lines ~280-360) =="
cat -n "$FILE" | sed -n '280,360p'

echo "== Context around return requestHandler cast (rough lines ~540-620) =="
cat -n "$FILE" | sed -n '540,620p'

echo "== Search TRegister/Register/RequestOptions/requestHandler in file =="
rg -n "TRegister|Register|RequestOptions<|requestHandler<|requestHandler\s*\(" "$FILE"

echo "== Search for definition/signature of requestHandler helper (generic signature) =="
rg -n "function requestHandler|const requestHandler|requestHandler\s*<" "$FILE"

Repository: TanStack/router

Length of output: 7191


🏁 Script executed:

#!/bin/bash
set -euo pipefail

FILE="packages/start-server-core/src/createStartHandler.ts"

echo "== Top of file (imports/types) =="
cat -n "$FILE" | sed -n '1,140p'

echo "== Search for RequestOptions type/import usage =="
rg -n "RequestOptions" "$FILE"

echo "== Search for RequestHandlerParameters or requestHandler helper import/identifier =="
rg -n "RequestHandlerParameters|requestHandler\b" "$FILE"

Repository: TanStack/router

Length of output: 5904


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Locate likely files
rg -n "export type RequestHandler|export interface RequestHandler|type RequestHandler" packages/start-server-core/src -S
rg -n "export type RequestOptions|interface RequestOptions|type RequestOptions" packages/start-server-core/src -S
rg -n "export function requestHandler|const requestHandler|function requestHandler" packages/start-server-core/src -S

# Print the relevant files (if found); fall back to targeted cat by resolving known paths
echo "== Try cat request-handler.ts =="
ls -1 packages/start-server-core/src | rg "request-handler"
if [ -f packages/start-server-core/src/request-handler.ts ]; then
  cat -n packages/start-server-core/src/request-handler.ts | sed -n '1,220p'
fi

echo "== Try cat request-response.ts =="
ls -1 packages/start-server-core/src | rg "request-response"
if [ -f packages/start-server-core/src/request-response.ts ]; then
  cat -n packages/start-server-core/src/request-response.ts | sed -n '1,260p'
fi

# If filenames differ, show a short list of matches
echo "== Show matches for request-handler import path =="
rg -n "from '\\./request-handler'|from \"\\./request-handler\"" packages/start-server-core/src/createStartHandler.ts

Repository: TanStack/router

Length of output: 13081


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Find the definition of Register in start-client-core (in-repo)
rg -n "export (type|interface) Register" packages/start-client-core -S
rg -n "type Register|interface Register" packages/start-client-core -S

# Also inspect server.requestContext typing if nearby
rg -n "requestContext" packages/start-client-core -S

Repository: TanStack/router

Length of output: 41


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Search repo for Register definition =="
rg -n "export (type|interface) Register|type Register\s*=" . -S

echo "== Search repo for requestContext typing =="
rg -n "requestContext" . -S

Repository: TanStack/router

Length of output: 1991


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect Register type
FILE1="packages/router-core/src/router.ts"
echo "== router-core Register (around its definition) =="
rg -n "export interface Register|export type Register" "$FILE1"
start=$(rg -n "export interface Register" "$FILE1" | head -n1 | cut -d: -f1)
end=$((start+60))
sed -n "${start},${end}p" "$FILE1" | cat -n

# Inspect createStartHandler around executeMiddleware and requestOpts?.context usage
FILE2="packages/start-server-core/src/createStartHandler.ts"
echo "== createStartHandler executeMiddleware context usage (around ~510-590) =="
cat -n "$FILE2" | sed -n '500,590p'

Repository: TanStack/router

Length of output: 6008


Avoid casting RequestHandler<Register> to RequestHandler<TRegister> in createStartHandler

startRequestResolver is typed as RequestHandler<Register> with requestOpts?: RequestOptions<Register> (325-327), but RequestOptions<TRegister> can require context when TRegister defines server.requestContext. Casting the result to RequestHandler<TRegister> (588) masks that constraint from callers.

Proposed type-safe fix
-  const startRequestResolver: RequestHandler<Register> = async (
-    request: Request,
-    requestOpts?: RequestOptions<Register>,
-  ) => {
+  const startRequestResolver: RequestHandler<TRegister> = async (
+    ...args: RequestHandlerParameters<TRegister>
+  ) => {
+    const [request, requestOpts] = args
     let router: AnyRouter | null = null as AnyRouter | null
     let cbWillCleanup = false as boolean
@@
-  return requestHandler(startRequestResolver) as RequestHandler<TRegister>
+  return requestHandler<TRegister>(startRequestResolver)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/start-server-core/src/createStartHandler.ts` around lines 325 - 327,
startRequestResolver is declared as RequestHandler<Register> with requestOpts?:
RequestOptions<Register>, but the code later casts it to
RequestHandler<TRegister>, which hides RequestOptions<TRegister> constraints
such as required server.requestContext; instead make startRequestResolver
generic over TRegister (or accept RequestOptions<TRegister>) within
createStartHandler so its signature matches RequestHandler<TRegister> without
casting—update the function/type parameters (startRequestResolver,
RequestOptions, RequestHandler, createStartHandler, TRegister, Register) so the
resolver uses the generic TRegister request option types (including
requestContext when present) and remove the unsafe cast.

Comment on lines +125 to +128
return ((
request: Request,
requestOpts?: any,
): Promise<Response> | Response => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify unsafe typing in wrapper signatures
rg -n -C2 'requestOpts\?: any|as RequestHandler<|RequestHandlerParameters<' packages/start-server-core/src/request-response.ts

Repository: TanStack/router

Length of output: 342


requestOpts?: any bypasses the handler type guarantees (and is masked by a cast).

In packages/start-server-core/src/request-response.ts, the wrapper takes requestOpts?: any (line 127) and then relies on as RequestHandler<TRegister> (line 146) to restore typing. This defeats strict type safety for the TRegister-specific opts contract. Replace any with the correct typed parameters for TRegister and remove/avoid the cast by aligning the wrapper’s parameter/return types with RequestHandler<TRegister] directly.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/start-server-core/src/request-response.ts` around lines 125 - 128,
The wrapper currently declares requestOpts?: any which bypasses the
RequestHandler<TRegister> contract and then re-establishes types via a cast;
change the wrapper signature to accept the strongly-typed options instead of any
so the wrapper itself matches RequestHandler<TRegister> (i.e., replace
requestOpts?: any with the correct generic opts type for TRegister and adjust
the wrapper return type to Promise<Response> | Response as needed), remove the
subsequent as RequestHandler<TRegister> cast, and ensure the internal call sites
use the typed opts variable (references: the wrapper function taking (request:
Request, requestOpts), the RequestHandler<TRegister> type and the TRegister
generic).

Copy link
Copy Markdown
Contributor

@nx-cloud nx-cloud Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

At least one additional CI pipeline execution has run since the conclusion below was written and it may no longer be applicable.

Nx Cloud is proposing a fix for your failed CI:

We updated type-only-protected-import.tsx to remove the Record<string, never> generic argument from RequestHandler<Record<string, never>>, which no longer satisfies the new TRegister extends Register constraint introduced by this PR. Using RequestHandler without a type argument falls back to the default Register type, which both satisfies the constraint and preserves the test's original intent of verifying that type-only imports of server types are safe from the import-protection plugin.

Tip

We verified this fix by re-running tanstack-react-start-e2e-import-protection:build, tanstack-react-start-e2e-import-protection:build:vite:ssr.

diff --git a/e2e/react-start/import-protection/src/routes/type-only-protected-import.tsx b/e2e/react-start/import-protection/src/routes/type-only-protected-import.tsx
index 8f208026..d4a17a17 100644
--- a/e2e/react-start/import-protection/src/routes/type-only-protected-import.tsx
+++ b/e2e/react-start/import-protection/src/routes/type-only-protected-import.tsx
@@ -3,7 +3,7 @@ import { type RequestHandler } from '@tanstack/react-start/server'
 import type { TypeOnlySecret } from '../violations/type-only.server'
 
 type TypeOnlyStatus = TypeOnlySecret & {
-  requestHandler?: RequestHandler<Record<string, never>>
+  requestHandler?: RequestHandler
 }
 
 const status: TypeOnlyStatus = {

Apply fix via Nx Cloud  Reject fix via Nx Cloud


Or Apply changes locally with:

npx nx-cloud apply-locally 5NcI-t5LF

Apply fix locally with your editor ↗   View interactive diff ↗



🎓 Learn more about Self-Healing CI on nx.dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant